<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<div class="aui-fullpage">
    <div class="aui-block vm-container">
        <lv-group class="group">
            <lv-group class="left" lvDirection='vertical'>
                <div class="aui-operation">
                    <lv-group lvGutter="16px">
                        <lv-pro-button-group [config]="optsConfig" [bindData]="treeSelection" [maxDisplayItems]="2">
                        </lv-pro-button-group>
                        <button lv-button lvSize="auto" (click)="getTreeData()" class="aui-button-icon">
                            <i lv-icon="lv-icon-refresh" [lvColorState]="true"></i>
                        </button>
                    </lv-group>
                </div>
                <div class="tree-container">
                    <ng-container *ngIf="treeData.length;else noDataTpl">
                        <lv-tree lvCompareWith="uuid" lvSelectionAssociate="false" [lvData]='treeData' [(lvSelection)]="treeSelection"
                            lvSelectionMode='single' [lvBeforeSelected]="beforeSelected" (lvCheck)="nodeCheck($event)"
                            lvShowContentIcon (lvExpandedChange)="expandedChange($event)" [lvNodeTemplate]='nodeTpl'
                            [lvScroll]='virtualScroll.scrollParam' lvVirtualScroll>
                        </lv-tree>
                    </ng-container>
                </div>
            </lv-group>
            <div class="slip"></div>
            <lv-group class="right aui-paginator-container">
                <lv-tabs [(lvActiveIndex)]="activeIndex" class="right-tab aui-tab">
                    <lv-tab lvTitle="{{'protection_openstack_domain_label' | i18n}}({{domainTotal}})" [lvId]="'domain'"
                        *ngIf="!treeSelection.length || treeSelection[0]?.type === resourceType.OpenStack">
                        <aui-domain-list [treeSelection]="treeSelection[0]" (updateTable)="updateDomainTotal($event)">
                        </aui-domain-list>
                    </lv-tab>
                    <lv-tab lvTitle="{{'common_project_label' | i18n}}({{projectTotal}})" [lvId]="'project'"
                        *ngIf="!treeSelection.length || treeSelection[0]?.type === resourceType.OpenStack || treeSelection[0]?.type === resourceType.StackDomain">
                        <aui-openstack-list [treeSelection]="treeSelection[0]" [resType]="resourceType.OpenStackProject"
                            (updateTable)="updateProjectTotal($event)">
                        </aui-openstack-list>
                    </lv-tab>
                    <lv-tab lvTitle="{{'common_cloud_server_label' | i18n}}({{cloudHostTotal}})" [lvId]="'cloudHost'">
                        <aui-openstack-list [treeSelection]="treeSelection[0]"
                            [resType]="resourceType.OpenStackCloudServer" (updateTable)="updateHostTotal($event)">
                        </aui-openstack-list>
                    </lv-tab>
                    <lv-tab *ngIf="treeSelection.length && treeSelection[0]?.type === resourceType.StackProject"
                        lvTitle="{{'protection_cloud_groups_label' | i18n}} ({{cloudGroupTotal}})"
                        [lvId]="resourceType.CLOUD_GROUP">
                        <aui-virtualization-group [treeSelection]="treeSelection[0] || []"
                            [subUnitType]="dataMap.Resource_Type.openStackCloudServer.value"
                            (updateTable)="updateGroupTotal($event)"></aui-virtualization-group>
                    </lv-tab>
                </lv-tabs>
            </lv-group>
        </lv-group>
    </div>
</div>

<ng-template #noDataTpl>
    <div class="tree-no-data">
        <lv-empty lvDescription="{{'protection_vm_tree_no_data_label' | i18n}}"></lv-empty>
    </div>
</ng-template>

<ng-template #nodeTpl let-item>
    <div style="max-width: 200px;" lv-overflow>
        <span class="aui-gutter-row-xs">
            <i [lv-icon]="item.contentToggleIcon"></i>
        </span>
        <span [ngClass]="{'tree-node-offline': item.rootNodeLinkStatus === 0}">{{item.label}}</span>
    </div>
</ng-template>